package com.ypan.creator;

/**
 * @Author ypan
 * @Date on 2021/3/10  10:48
 * @Desc 抽象工厂模式主要设计产品组的概念，
 * 就是某一个工厂生产出配套的一系列产品。例如，在生产足球的同时，
 * SoccerFactory还可以生产与之配套的足球杂志。
 */
public class AbstractFactory {

    interface BallFactory {
        Ball createBall();
    }

    static class Ball {

        private String name;

        private Integer pnum;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getPnum() {
            return pnum;
        }

        public void setPnum(Integer pnum) {
            this.pnum = pnum;
        }

        @Override
        public String toString() {
            return "Ball{" +
                    "name='" + name + '\'' +
                    ", pnum=" + pnum +
                    '}';
        }
    }

    interface Journal {
        String create();
    }

    class FootBallJournal implements Journal{

        public String create() {
            return "足球真好玩";
        }
    }

    class FootBallFactory implements BallFactory {

        public Ball createBall() {
            Ball ball = new Ball();
            ball.setName("FootBall");
            ball.setPnum(12);
            return ball;
        }

        public Journal createJournal(){
            return new FootBallJournal();
        }

    }

}
